# serializer
from functools import wraps
from inspect import isawaitable
from quart import Blueprint, jsonify, render_template

# 序列化
def serializer(func):
    def decorator(f):
        @wraps(f)
        async def decorated_function(*args, **kwargs):
            retval = f(*args, **kwargs)
            if isawaitable(retval):
                retval = await retval
            return func(retval)
        return decorated_function
    return decorator


# 注册蓝图
def route(url, prefix='/'):
    name = url.split('.')[-1]
    if name == 'index':
        prefix = '/'
    else:
        prefix = '/'+name

    return Blueprint(name, url.replace('.', '_'), prefix)

# 公式：（当前页-1）*每页条数，每页条数
def page(page, limit=10):
    return (page-1)*limit
